package agents.utils;

import agents.utils.Order.Priority;
import jade.core.AID;
import java.io.Serializable;
import org.joda.time.DateTime;

/**
 * This class represents a single product to be produced in our production line.
 * It contains all information needed to store information about the product.
 * 
 * @author Group 6
 */
public class WorkPackage implements Serializable, Comparable<WorkPackage> {

    public static int numberWP = 0;
    
    // Variáveis e métodos de instância
    private int id;
    private int orderID;
    private WorkType workType;
    private AID machineAID;
    private DateTime deadline;
    private boolean done;
    private Priority priority;

    public WorkPackage(int orderId, WorkType toMachineType, DateTime deadline, Priority priority) {
        numberWP++;
        this.id = numberWP;
        this.orderID = orderId;
        this.workType = toMachineType;
        this.machineAID = null;
        this.deadline = deadline;
        this.done = false;
        this.priority = priority;
    }

    public int getId() {
        return id;
    }

    public int getOrderID() {
        return orderID;
    }

    public WorkType getWorkType() {
        return workType;
    }

    public void setWorkType(WorkType workType) {
        this.workType = workType;
    }

    public AID getMachineAID() {
        return machineAID;
    }

    public void setMachineAID(AID machineAID) {
        this.machineAID = machineAID;
    }

    public DateTime getDeadline() {
        return deadline;
    }

    public boolean isDone() {
        return done;
    }

    public Priority getPriority() {
        return priority;
    }

    public void processWork() {
        this.done = true;
    }

    @Override
    public int compareTo(WorkPackage o) {
        if (this.priority == o.priority) {
            //return this.deadline.compareTo(o.getDeadline());
            if (this.deadline.isAfter(o.deadline)) {
                return 1;
            } else if (this.deadline.isEqual(o.deadline)) {
                return 0;
            } else {
                return -1;
            }
        } else if ((this.priority == Priority.NORMAL) && (o.priority == Priority.HIGH)) {
            return 1;
        } else {
            return -1;
        }
    }
    
}